Skip to content

Implement feedback controller for redemption rate#142

Open
3esmit wants to merge 2 commits into
mainfrom
issue-95-feedback-controller
Open

Implement feedback controller for redemption rate#142
3esmit wants to merge 2 commits into
mainfrom
issue-95-feedback-controller

Conversation

@3esmit

@3esmit 3esmit commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add the stablecoin RedemptionController account, PDA helpers, and fixed-point gain scale.
  • Add initialize/update instructions and guest handlers for permissionless redemption-rate updates.
  • Compute signed P/PI redemption rates from oracle market price vs. redemption price using negative feedback, clamp integral state and rate, and pause updates when the configured feed is stale or unavailable.
  • Bind the controller feed to stablecoin/collateral oracle assets without pinning the oracle account's program owner.
  • Constrain controller instruction outputs to the supplied current_timestamp so oracle freshness is tied to execution time.

Closes #95.

3esmit added 2 commits June 8, 2026 11:24
…s for redemption rate feedback controller

- Added `initialize_redemption_controller` and `update_redemption_controller` functions to manage redemption rate feedback.
- Introduced `RedemptionController` struct to maintain state for redemption rates.
- Updated `Cargo.toml` and `Cargo.lock` to include `twap_oracle_core` dependency.
- Modified integration tests to cover new redemption controller functionality.
@3esmit 3esmit changed the title (draft) feedback controller for redemption rate Implement feedback controller for redemption rate Jun 15, 2026
@3esmit 3esmit marked this pull request as ready for review June 18, 2026 16:42
Copilot AI review requested due to automatic review settings June 18, 2026 16:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements an autonomous redemption-rate feedback controller (P/PI) that derives a signed redemption rate from an oracle market price vs. the current redemption price, with clamping and stale-oracle pausing behavior. This adds the required on-chain controller state + PDA helpers, guest instruction handlers, and integration tests to exercise initialize/update flows.

Changes:

  • Add RedemptionController account type, gain scaling constant, and PDA helpers; extend Stablecoin instruction enum with initialize/update controller instructions.
  • Implement host-side controller initialization + update logic using oracle price feeds with staleness checks, error integration clamping, and redemption rate clamping.
  • Add guest handlers that constrain outputs to the supplied current_timestamp, plus integration tests and required twap_oracle_core dependencies/IDL updates.

Reviewed changes

Copilot reviewed 8 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
programs/stablecoin/src/redemption_controller.rs New host implementation + unit tests for controller init/update and controller math.
programs/stablecoin/src/lib.rs Exposes the new redemption_controller module.
programs/stablecoin/methods/guest/src/bin/stablecoin.rs Adds guest instruction handlers for initialize/update with exact timestamp validity windows.
programs/stablecoin/methods/guest/Cargo.lock Pulls in twap_oracle_core via dependency resolution.
programs/stablecoin/core/src/lib.rs Adds controller account type, gain scale constant, PDA helpers, and instruction variants.
programs/stablecoin/Cargo.toml Adds twap_oracle_core dependency for oracle price decoding.
programs/integration_tests/tests/stablecoin.rs Adds end-to-end test covering controller initialize + update from a price feed.
programs/integration_tests/Cargo.toml Adds twap_oracle_core for integration tests.
Cargo.lock Workspace lockfile updates for new dependency edges.
artifacts/stablecoin-idl.json Updates IDL to include the new instructions and account type.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +5 to +9
use stablecoin_core::{verify_redemption_controller_and_get_seed, RedemptionController};
use token_core::TokenDefinition;
use twap_oracle_core::OraclePriceAccount;

const CONTROLLER_GAIN_SCALE_I128: i128 = 1_000_000_000;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement feedback controller for redemption rate

2 participants